import Vue from "vue"
import Vuex from "vuex"
import createPersistedState from 'vuex-persistedstate'
// import Lang from '../assets/lang'
Vue.use(Vuex);
const store = new Vuex.Store({
  state: {
    //验证码
    identifyCode: '1234567890',
    //面包导航
    breadcrumb: [{
      name: '首页',
      path: '/'
    }],
    //操作员昵称
    nickName: '',
    adminType: '',
    //token
    access_token: '',
    //
    activeMenu: '',
    // 请求环境
    baseUrl: 'http://10.40.92.236:9066',
    //header
    headerObj: {
      access_token: ''
    },
    menuList: [],
    tagsList: [],
  },
  getters: {
    //监听验证码改变
    getIdentifyCode: function (state) {
      
      return state.identifyCode
    },
    //监听操作员昵称
    getNickName: function (state) {
      return state.nickName
    },
    //token
    getAccessToken: function (state) {
      return state.access_token
    },
  },
  mutations: {
    //http  https
    refreshNewHttp(state, baseUrl) {
      state.baseUrl = baseUrl
      console.log('baseUrl', state.baseUrl)
    },
    //改变验证码数据
    refreshNewCode(state, identifyCode) {
      state.identifyCode = identifyCode
    },
    //操作账户
    refreshNickName(state, nickName) {
      state.nickName = nickName
    },
    refreshAdminType(state, adminType) {
      state.adminType = adminType
    },
    //token
    refreshAccessToken(state, access_token) {
      state.access_token = access_token
      state.headerObj.access_token = access_token
    },
    //
    refreshActiveMenu(state, activeMenu) {
      state.activeMenu = activeMenu
    },
    //
    refreshMenuList(state, menuList) {
      console.log("menuList",menuList)
      state.menuList = menuList
    },
    refreshTagList(state, tagsList) {
      state.tagsList = tagsList
    },

  },
  plugins: [createPersistedState({
    storage: window.sessionStorage
  })]
})

export default store